<?php
/**
 * Created by PhpStorm.
 * User: dust2
 * Date: 14-12-21
 * Time: 上午12:08
 */

/**
 * Class Linkage
 * 中国省市县(区)三级联动模型
 */
class Linkage extends Eloquent
{
    protected $table = 'linkages';
    public $timestamps = false;

    protected $guarded = array();


    /**
     * 根据当前地区id获取下级地区信息
     * @param int $curr_id
     * @return $this
     */
    public static function getAddressesBySuperId($curr_id = 0)
    {
        $columns = ['id', 'name'];
        return DB::table('linkages')->where('sup_id', $curr_id)->select($columns)->get();
    }

    /**
     * 根据当前地区id获取当前地区信息
     * @param $curr_id
     * @return $this
     */
    public static function getAddressById($curr_id)
    {
        $columns = ['id', 'name'];
        $address_obj = Linkage::where('id', $curr_id)->select($columns)->get()->toArray();
        return $address_obj[0];
    }

    /**
     * 获取上级地区id
     * @param $curr_id
     * @return $this
     */
    public static function getSuperId($curr_id)
    {
        $super_obj = Linkage::where('id', $curr_id)->select('sup_id')->get()->toArray();
        return $super_obj[0]['sup_id'];
    }

}